﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Baza.EF.DAL;

namespace Baza.EF.BLL
{
   public class DAIznajmljivaciApartmani
    {
        public static void InsertOwners(Owners owner) {

            Connection.dm.ad_Owners_ISNERT(owner.FirstName, owner.LastName,owner.Email,owner.AdresID, owner.CellNumber, owner.BusinessNumber, owner.HomeNumber, owner.FaxNumber, owner.AdditionalContactInfo, owner.WebsiteURL, owner.PasswordSalt, owner.PasswordHash,owner.AboutMe,owner.Photo);
                
        }

        public static void UpdateOwners(Owners owner)
        {

            Connection.dm.sp_AdriaDay_Owners_Update(owner.OwnerID,owner.FirstName, owner.LastName, owner.Email, owner.AdresID, owner.CellNumber, owner.BusinessNumber, owner.HomeNumber, owner.FaxNumber, owner.AdditionalContactInfo, owner.WebsiteURL, owner.PasswordSalt, owner.PasswordHash);

        }

        public static List<Countries> SelectCountries() {

            return Connection.dm.sp_AdriaDay_Countries_SellectAll().ToList();
        
        }


        public static void InsertApartment(Apartments apartment, Owners owner){

           


            int apartmentID = Convert.ToInt32(Connection.dm.ad_Owners_Apartments_INSERT(apartment.Title, apartment.ApartmentTypeID, apartment.Bathrooms, apartment.Toilets, apartment.MaxGuests, apartment.MaxAdults, apartment.MaxChildren, apartment.MaxBabies, apartment.AdresID, apartment.CheckIn, apartment.CheckOut, apartment.Floor, apartment.Elevator, apartment.AvgCleaningTime, apartment.MinStay, apartment.MaxStay, apartment.RentalDetails, apartment.Inventory, apartment.ArrivalSheet, apartment.Beds, apartment.Bedrooms, "--").First());

            Connection.dm.ad_Owners_Apartment_OwnerIDApartmanID(apartmentID, owner.OwnerID);


            
        }

        public static List<Owners> SelectOwners()
        {

            return Connection.dm.sp_AdriaDay_Owners_SellectAll().ToList(); ;

        }


        public static List<Apartments> SelectApartmentBYOwner(Owners owner) 
        {
            return Connection.dm.sp_AdriaDay_Apartments_Select_BY_OwnerID(owner.OwnerID).ToList();
        }


        public static void RemoveApartmentByID(Apartments apartment)
        {
              Connection.dm.sp_AdriaDay_Apartments_RemoveApartment_BY_ID(apartment.ApartmentID);
        }

        public static List<Apartments> SelectAllApartments()
        {

            return Connection.dm.sp_AdriaDay_Apartments_SellectAll().ToList();
        }


        public static List<Reservations> SelectAllReservations() 
        {

            return Connection.dm.sp_AdriaDay_Reservations_SellectAll().ToList();

        }

        //public static List<Reservations> SelectReservationBYApartment(Apartments apartment) 
        //{

        //    return Connection.DM.sp_AdriaDay_Reservations_Sellect_BY_Apartment(apartment.ApartmentID).ToList();
            
        //}

        public static List<Reservations> SelectActiveReservations()
        {

            return Connection.dm.sp_AdriaDay_Reservations_SelectActiveReservations().ToList();

        }

        public static List<Reservations> SelectReservationBYCustomer(int customerID)
        {

            return Connection.dm.sp_AdriaDay_Reservations_Sellect_BY_Customer(customerID).ToList();

        }

        public static void RemoveReservation(int ReservationID)
        {
            
            Connection.dm.sp_AdriaDay_Reservations_Remove_BY_ID(ReservationID);

        }


        public static void ReservationsInsert(Reservations reservation,int ApartmentID,int CustomerID) 
        {

            int ReservationID = Convert.ToInt32(Connection.dm.sp_AdriaDay_Reservations_Insert(reservation.CheckIn, reservation.CheckOut, reservation.Price).First());

            Connection.dm.sp_AdriaDay_Reservations_Customers_Insert(ApartmentID, CustomerID, ReservationID);
        }


        public static List<ApartmentType> ApartmentTypeSelect() {

           return  Connection.dm.ad_Owners_ApartmentType_SELECT().ToList();
        }


        public static int ApartmentAddressInsert(Address address){
        
           int addressID = Convert.ToInt32(Connection.dm.ad_Address_INSERT(address.CityID,address.StreetNumber,address.Address1,address.Address2,address.ApartmentNumber).First());
            
           return addressID;
        }

        public static List<Cities> SelectCities()
        {

            return Connection.dm.ad_Cities_Select().ToList();
        
        }

        public static List<Address> SelectAddresBYAddresID(int addresID)
        {

            return Connection.dm.ad_Owners_Apartmans_Get_Address_By_AddresID(addresID).ToList();

        }

        public static List<ApartmentType> SelectApartmentTypeByID(int apartmentTypeID)
        {
            //ima error ne postoji procedura ova
            //return Connection.dm.ad_Owners_ApartmentType_select_by_apartmentTypeID(apartmentTypeID).ToList();
            return null;

        }

        public static void RemoveOwnerBYID(int OwnerID)
        {

            Connection.dm.sp_AdriaDay_Owners_Remove_BY_ID(OwnerID);

        }

        public static List<Reservations> SelectReservationBYApartment(Apartments apartment)
        {
            return  Connection.dm.sp_AdriaDay_Reservations_Sellect_BY_Apartment(apartment.ApartmentID).ToList();
        }

    }
}
